package com.factory.factorymethod.pizzastore.order;


import com.factory.factorymethod.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/4/13 10:02
 */
public abstract class OrderPizza {

    abstract Pizza createPizza(String orderType);
    
    public OrderPizza(){
        Pizza pizza = null;
        String orderType;
        do {
            orderType = getType();
            // 抽象方法，由工厂子类完成
            pizza = createPizza(orderType);
            // 输出pizza
            if (pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                break;
            }
        } while (true);
    }
    
    // 写一个方法，可以动态的获取客户希望订购的披萨种类
    private String getType(){
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = br.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
    
}
